/*
 * Copyright 2012 Sedov Eduard.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.es.registry;

import java.util.Set;

/**
 * The interface to monitor changes of a registry.
 *
 * @author Sedov Eduard
 */
public interface RegistryListener {

    /**
     * Called if {@link Registry#cd()} called.
     *
     * @param registry the registry whose method is called
     * @param currentName name of current directory
     */
    public void onCd(Registry registry, String currentName);
    
    /**
     * Called if {@link Registry#cd(java.lang.String)} called.
     *
     * @param registry the registry whose method is called
     * @param oldName name of old current directory
     * @param newName name of new current directory
     */
    public void onCd(Registry registry, String oldName, String newName);

    /**
     * Called if {@link Registry#mkdir(java.lang.String)} called.
     *
     * @param registry the registry whose method is called
     * @param name name of created directory
     */
    public void onMkdir(Registry registry, String name);

    /**
     * Called if {@link Registry#rmdir(java.lang.String)} called.
     *
     * @param registry the registry whose method is called
     * @param name name of removed directory
     */
    public void onRmdir(Registry registry, String name);

    /**
     * Called if {@link Registry#get(java.lang.String)} called.
     *
     * @param <T> the type of value
     * @param registry the registry whose method is called
     * @param name the path
     * @return the value or {@code null} if no value set
     */
    public <T> void onGet(Registry registry, String name, T value);

    /**
     * Called if {@link Registry#put(java.lang.String, java.lang.Object)} called.
     *
     * @param <T> the type of value
     * @param registry the registry whose method is called
     * @param name the relative or absolute path
     * @param oldValue the previous value
     * @param newValue the new value
     */
    public <T> void onPut(Registry registry, String name, T oldValue, T newValue);

    /**
     * Called if {@link Registry#delete(java.lang.String)} called.
     *
     * @param <T> the type of deleted value
     * @param registry the registry whose method is called
     * @param name the name
     * @param value the value
     */
    public <T> void onDelete(Registry registry, String name, T value);
    
    /**
     * Called if {@link Registry#list()} called.
     *
     * @param registry the registry whose method is called
     * @param result a set of names
     */
    public void onList(Registry registry, Set<String> result);

    /**
     * Called if {@link Registry#rename(java.lang.String, java.lang.String)} called.
     *
     * @param registry the registry whose method is called
     * @param oldName old name
     * @param newName new name
     */
    public void onRename(Registry registry, String oldName, String newName);
}
